package com.smasher.doc.operation;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Message;

import com.smasher.core.other.WeakReferenceHandler;
import com.smasher.doc.R;
import com.smasher.doc.entity.CacheEntity;

public class WorkTaskReadUri implements Runnable, OperationReadHelper.Callback {

    private final ContentResolver contentResolver;
    private final WeakReferenceHandler handler;
    private final Uri uri;
    private final OperationReadHelper operationReadHelper = new OperationReadHelper(this);

    public static final int MSG_END = 1001;

    public WorkTaskReadUri(Context context, WeakReferenceHandler handler, Uri uri) {
        this.contentResolver = context.getContentResolver();
        this.handler = handler;
        this.uri = uri;
    }

    @Override
    public void run() {
        operationReadHelper.readDocFromUri(contentResolver, uri);
    }

    @Override
    public void onReady(CacheEntity entity) {
        Message message = handler.obtainMessage();
        message.what = MSG_END;
        message.obj = entity;
        handler.sendMessage(message);
    }
}
